<?php

namespace App\Models\Game\Settlement;

use App\Models\Game\Model;
use App\Models\Elasticsearch\Settlement\Detail as EsDetail;

class Detail extends Model
{

    /**
     * 数据表名称
     *
     * @var string
     */
    protected $table = 't_settlement_detail';

    /**
     * 进行类型转换的字段
     *
     * @var array
     */
    protected $casts = [
        'ext' => 'array',
        'details' => 'array',
        'ctrl' => 'array',
        'rtp_control' => 'array',
    ];

    /**
     * 获取游戏详情
     *
     * @param string $roundId
     * @return array|null
     */
    protected function getDetail(string $roundId): ?array
    {
        if (!config('elasticsearch.default')) {
            $detail = $this->newQuery()->where('round_id', $roundId)->first();

            return $detail ? $detail->toArray() : null;
        } else {
            return EsDetail::getDetail($roundId);
        }
    }
}
